<template>
  <div>
    <!--工具栏-->
    <div class="head-container">
      <!-- 搜索 -->
      <el-input v-model="query.blurry" clearable size="small" placeholder="输入编码或者名称搜索" style="width: 200px;"
                class="filter-item" @keyup.enter.native="toQuery"/>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
      <el-button class="filter-item" v-if="checkPermission(['appMutex:add'])" size="mini" type="danger" icon="el-icon-delete" @click="delMutexTask">删除互斥
      </el-button>
    </div>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" style="width: 100%;"
              @selection-change="selectionLineChangeHandle"
              :header-cell-style="{ background: 'rgba(52, 125, 225, 0.1)', color: '#404248' }" border stripe>
      <el-table-column type="selection"/>
      <el-table-column prop="taskCode" label="任务编码"/>
      <el-table-column prop="taskName" label="任务名称"/>
      <el-table-column prop="resNum" label="资源数"/>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      :current-page="page + 1"
      style="margin-top: 8px;"
      layout="prev, pager, next, sizes,total"
      @size-change="sizeChange"
      @current-change="pageChange"
      :pager-count="3" prev-text=" " next-text=" "
    />
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import mutexApi from '@/api/mutexPool/mutex'
import checkPermission from '@/utils/permission' // 权限判断函数

export default {
  mixins: [crud],
  data() {
    return {
      title: '互斥任务列表',
      sort: ['sort,asc', 'id,desc'],
      dictName: '',
      form: {id: null, label: null, value: null, defaultParam: null, dict: {id: null}, sort: 999},
      rules: {
        label: [
          {required: true, message: '请输入字典标签', trigger: 'blur'}
        ],
        value: [
          {required: true, message: '请输入字典值', trigger: 'blur'}
        ],
        sort: [
          {required: true, message: '请输入序号', trigger: 'blur', type: 'number'}
        ]
      },
      totalElements: 0,
      dataonLineListSelections: [],
    }
  },
  methods: {
    checkPermission,
    // 获取数据前设置好接口地址
    beforeInit() {
      this.url = 'api/periodTaskDef/findMutexTaskList'
      return true
    },
    selectionLineChangeHandle(val) {
      this.dataonLineListSelections = val
    },
    delMutexTask() {
      if (this.dataonLineListSelections.length > 0) {
        let taskCodeList = [];
        for (var i = 0; i < this.dataonLineListSelections.length; i++) {
          taskCodeList.push(this.dataonLineListSelections[i].taskCode);
        }
        this.$confirm(`确认删除选中的${taskCodeList.length}条任务吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let params = {taskCodes: taskCodeList}
          mutexApi.appDelMutexPool(params).then(() => {
            this.$notify({message: '删除成功', type: 'success'});
            this.init();
          }).catch((res) => {
            this.$notify.error({title: '删除失败', message: res.response.data});
          })
        }).catch(() => {
        })
      } else {
        this.$notify({title: '警告', message: '请选择至少一条任务', type: 'warning'});
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep .el-input-number .el-input__inner {
  text-align: left;
}
</style>
